﻿using System;
using PQ.Util;
namespace PQ.Util
{
    class Program
    {
        static void Mains(string[] args)
        {
         /*  int hDevice = USB1612M.USB1612M_OpenDevice(0);
           
           Console.WriteLine(hDevice);
            //初始化
           USB1612M.USB1612M_ADInit(hDevice);
           IntPtr a = new IntPtr(0);
           bool t =true;
           t = USB1612M.USB_VENDOR_OR_CLASS_REQUEST(hDevice, 0xb3, 0x00, 0, a);
           Console.WriteLine(t);
           //清空FIFO
           USB1612M.USB1612M_CLRFIFO(hDevice);

           //设置同步通道
           USB1612M.USB1612M_SetADCh(hDevice, 1);
           //设置采样频率
           USB1612M.USB1612M_SetADFre(hDevice, 7);
           //设置工作模式
           USB1612M.USB1612M_SetADMode(hDevice, 1);


           //允许传输
           t = USB1612M.USB1612M_IOCTL_VENDOR_REQUEST(hDevice, 0xB2);
           Console.WriteLine(t);
           //启动AD
          t = USB1612M.USB1612M_ADStart(hDevice);
          Console.WriteLine(t);
           Console.WriteLine(USB1612M.xc_GetVersion());
           byte[] buck = new byte[18432];
          // IntPtr buck = new IntPtr(1110);
           uint realSize =0;
           while (true)
           {
               t = USB1612M.USB1612M_IOCTL_BULK_READ(hDevice,  buck, (uint)18432, ref realSize);
               Console.WriteLine(t);
              Console.WriteLine( realSize);
           }
           while (USB1612M.USB1612M_IOCTL_BULK_READ(hDevice,  buck, (uint)18432, ref realSize))
           {
               for (int i = 0; i < realSize; i++)
               {
                   Console.Write(buck[i] + " ");
               }
               Console.WriteLine();
           }*/
            int a = 18432;
             byte[] buck = new byte[a];
             byte[,] tb = new byte[2,2];
             // IntPtr buck = new IntPtr(1110);
             uint realSize = 0;
             USB1612M u = new USB1612M();
             u.OpenDevice();
             u.StartSample(USB1612M.CH12,USB1612M.Fre200KHz,USB1612M.SoftwareTrigger);
             double[][] data;
             int sec=-1;
             int count = 0;
            
             double timeIntvl=0.0;
             while (true)
             {
                 
             //    //data = u.Read();
              //   timeIntvl += u.pointNum * 1d/(200d*1024d)*1000d;
                 if (count++ % 500 == 0)
                 {
                     DateTime d = u.startDateTime.AddMilliseconds(timeIntvl);
                     Console.WriteLine(DateTime.Now + "." + DateTime.Now.Millisecond);
                     Console.WriteLine(d + "." + d.Millisecond);
                 }
                 /*
                 startTime += Convert.ToInt64(u.pointNum/0.0200f);

               //  Console.WriteLine(startTime);
                 
               //Console.WriteLine(d + "." + d.Millisecond);
                 if (sec == DateTime.Now.Second)
               {
                   count += u.pointNum;
               }
               else
               {
                   Console.WriteLine(count);
                   count = 0;
                   sec = DateTime.Now.Second;
                   Console.WriteLine(DateTime.Now+"."+DateTime.Now.Millisecond);
                   Console.WriteLine(new DateTime(startTime) + "." + new DateTime(startTime).Millisecond);
               }
                 
                 for (int i = 0; i < 10; i++)
                 {
                     Console.Write(data[0, i]+" ");
                 }
                 Console.WriteLine();
                 for (int i = 0; i < 10; i++)
                 {
                     Console.Write(data[1, i] + " ");
                 }
                 Console.WriteLine();
                 for (int i = 0; i < 10; i++)
                 {
                     Console.Write(data[6, i] + " ");
                 }
                 Console.WriteLine();
                 for (int i = 0; i < 10; i++)
                 {
                     Console.Write(data[7, i] + " ");
                 }
                 Console.WriteLine();*/
             }
            /*
             float[] a = {
                 0.5751f,0.4514f,0.0439f,0.0272f,0.3127f,0.0129f,0.3840f,0.6831f,
                 0.0928f,0.0353f,0.6124f ,0.6085f,0.0158f,0.0164f,0.1901f,0.5869f};
             float[] b = {
                 0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,
                 0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};

              a =new float[] {
                 0.5751f,0.4514f,0.0439f,0.0272f,0.3127f,0.0129f,0.3840f,0.6831f,
                 0.00f,0.00f,0.0f ,0.0f,0.00f,0.0f,0.0f,0.0f};
              b = new float[]{
                 0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,
                 0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f};
           
             int n = TWFFT.FFT(a,b);
             Console.WriteLine("FFT:");
             Console.WriteLine("FFT的返回值N = {0}", n);
             Console.WriteLine();
             Console.WriteLine("i\ta\tb");
             Console.WriteLine();
             for (int i = 0; i < n; i++)
             {
                 Console.WriteLine("{0}\t{1}\t{2}", i, a[i], b[i]);
             }
             Console.ReadLine();*/
            Console.Read();
        }
    }
}
